﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;

namespace PortalWeb.Core.IManager
{
    public interface IGenericManager<T> where T : class, new()
    {
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        T Get(object id);

        /// <summary>
        /// 实现对数据库的添加功能,添加实现EF框架的引用
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Add(T entity);

        /// <summary>
        /// 实现对数据库的修改功能
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(T entity);


        /// <summary>
        /// 实现对数据库的删除功能
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Delete(T entity);

        int Count();

        /// <summary>
        /// 实现对数据库的查询  --简单查询
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        IEnumerable<T> LoadEntities(Expression<Func<T, bool>> whereLambda);

        Task<T[]> LoadEntitiesAsync(Expression<Func<T, bool>> whereLambda);

        Task<T> GetAsync(object id);

        Task<T[]> LoadAllEntitiesnAsync();

        Task<T[]> LoadPageEntitiesAsync<TS>(Expression<Func<T, bool>> whereLambda, bool b,Expression<Func<T, TS>> orderByLambda, int offset, int limint);

        Task<T[]> LoadPageEntitiesAsync(Expression<Func<T, bool>> whereLambda, string order, string sort, int offset,int limit);
        Task<IdentityResult> CreateAsync(T entity);
        Task<IdentityResult> UpdateAsync(T entity);
        Task<IdentityResult> DeleteAsync(T entity);
    }
}